<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/web/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>订单</title>
<link href="${ctx}/assets/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/assets/js/jquery.js"></script>
</head>
<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">订单</a></li>
    </ul>
    </div>
    
    <div class="rightinfo">
    
    <div class="tools">
    
    	<ul class="toolbar">
        <li class="click"><span>
        <img src="${ctx}/assets/images/t01.png" /></span>
        	<a href="${ctx}/admin/order/add">新增订单</a>
        </li>
        </ul>
    </div>
    <table class="tablelist">
    	<thead>
    	<tr><th>序号</th>
        <th>订单号</th>
        <th>车主</th>
        <th>车主手机</th>
        <th>创建时间</th>
        <th>状态</th>
        <th>操作</th>
        </tr>
        </thead>
        <tbody>
        	<c:forEach var="obj" items="${page.list}" varStatus="vs">
        		<tr>
				<td>${vs.index + 1 + (page.pageSize * (page.pageNum - 1))}</td>
		        <td>${obj.taobaoorderid}</td>
		        <td>
		        	${obj.linkname}
		        </td>
		        <td>
		        	${obj.linkmobile}
		        </td>
		        <td>
		        	<fmt:formatDate value="${obj.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>
		        </td>
		        <td>
					<c:choose>
						<c:when test="${obj.state eq 0}">
							新订单
						</c:when>
						<c:when test="${obj.state eq 1}">
							未安装
						</c:when>
						<c:when test="${obj.state eq 2}">
							未核销
						</c:when>
						<c:when test="${obj.state eq 3}">
							待回访
						</c:when>
						<c:when test="${obj.state eq 31}">
							售后中
						</c:when>
						<c:when test="${obj.state eq 100}">
							订单结束
						</c:when>
					</c:choose>
				</td>
		        <td>
			        <a href="${ctx}/admin/order/view/${obj.id}" class="tablelink">查看</a>     
			        <a href="${ctx}/admin/order/edit/${obj.id}" class="tablelink">修改</a>
			        <a href="javascript:confirmDelete('${obj.id}')" class="tablelink">删除</a>
		        </td>
		        </tr> 
        	</c:forEach>
        </tbody>
    </table>
   
    <div class="pagin">
    	<div class="message">共<i class="blue">${page.total}</i>条记录，当前显示第&nbsp;<i class="blue">${page.pageNum}&nbsp;</i>页</div>
        <ul class="paginList">
        <li class="paginItem"><a href="javascript:;">首页</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem current"><a href="javascript:;">${page.pageNum}</a></li>
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
        <li class="paginItem"><a href="javascript:;">末页</a></li>
        </ul>
    </div>
    </div>
    <script type="text/javascript">
    var confirmDelete = function(id) {
    	if (confirm('确定删除吗？')) {
    		// 处理删除的代码
    		location.href = '${ctx}' + "/admin/order/delete?id=" + id;
    	}
    }
    
	$('.tablelist tbody tr:odd').addClass('odd');
	$(function() {
		function goPage(page) {
			location.href = '${ctx}/admin/order/list?currentPage=' + page;
		}
		
		$('.paginItem:first').click(function() {
			// 实现首页
			goPage(1);
		});
		
		$('.pagepre').click(function() {
			// 实现上一页
			var currentPage = '${page.pageNum}';
			if (parseInt(currentPage) <= 1) {
				currentPage = 1;
			} else {
				currentPage = parseInt(currentPage) - 1;
			}
			goPage(currentPage);
		});
		
		$('.pagenxt').click(function() {
			// 实现下一页
			var currentPage = '${page.pageNum}';
			var total = parseInt('${page.total}');
			var pageSize = parseInt('${page.pageSize}');
			var maxPage = parseInt((total - 1) / pageSize) + 1;
			if (currentPage >= maxPage) {
				currentPage = maxPage;
			} else {
				currentPage = parseInt(currentPage) + 1;
			}
			goPage(currentPage);
		});
		
		$('.paginItem:last').click(function() {
			// 实现末页
			var total = parseInt('${page.total}');
			var pageSize = parseInt('${page.pageSize}');
			var maxPage = parseInt((total - 1) / pageSize) + 1;
			goPage(maxPage);
		});
	});
	
	if ("${successMessage}") {
		alert("${successMessage}");
	}
	if ("${errorMessage}") {
		alert("${errorMessage}");
	}
	</script>
</body>
</html>
